package samsung.sds.survey.surveyStatistics.controller;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import samsung.sds.survey.surveyStatistics.model.UserAnswerStatus;
import samsung.sds.survey.surveyStatistics.service.UserAnswerStatusService;
import samsung.sds.system.common.baseQuery.model.PageData;
import samsung.sds.system.common.model.QueryParam;
import samsung.sds.system.utils.CommonTools;
/**
 * @author  hulongtao 
 * @createDate 2016/01/27
 * */
@Controller
@RequestMapping("/survey/surveyStatistics/userAnswerStatus")
public class UserAnswerStatusController {
	@Autowired
	private UserAnswerStatusService userAnswerStatusServiceImpl;

	/**
	 * 获得报表明细数据
	 * 
	 * @param request
	 * */
	@RequestMapping(value="/showDetailData",method=RequestMethod.POST )
	@ResponseBody
	public PageData<UserAnswerStatus> showPageListOfDetail(HttpServletRequest request) {
		QueryParam param = CommonTools.getQueryParam(request);
		return this.userAnswerStatusServiceImpl.queryListPage(param);
	}

	/**
	 * 获得报表头汇总数据
	 * @param surveyId
	 * */
	@RequestMapping(value="/showDetailHead", method=RequestMethod.POST)
	@ResponseBody
	public UserAnswerStatus showHeadOfDetail(
			@RequestParam(value = "surveyId", required = false) String surveyId){
		UserAnswerStatus userAnswerStatus = new UserAnswerStatus();
		userAnswerStatus.setSurveyId(new String(surveyId));
		return this.userAnswerStatusServiceImpl.getDetailInfo(userAnswerStatus);
	}

	/**
	 * 获得饼图的数据
	 * @param surveyId
	 */
	@RequestMapping(value="/getPieData",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Integer> getPieData(
			@RequestParam(value = "surveyId", required = true) String surveyId) {
		return this.userAnswerStatusServiceImpl.getPieInfo(surveyId);
	}

	/**
	 * 问卷数据导出《包含报表汇总数据和明细数据》
	 * 
	 * @param userAnswerStatus
	 * @throws request
	 * @throws response
	 * @throws Exception 
	 * */
	@RequestMapping(value="/answerExport",method=RequestMethod.POST)
	public void processVotedUserExport(UserAnswerStatus userAnswerStatus,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		this.userAnswerStatusServiceImpl.processVotedUserExport(request, response,
				userAnswerStatus);
	}

	 
}
